package com.mingnew.ecache.controller;

import com.mingnew.ecache.entity.Employee;
import com.mingnew.ecache.entity.dto.EmployeeDto;
import com.mingnew.ecache.entity.dto.PageDto;
import com.mingnew.ecache.entity.vo.EmployeeVo;
import com.mingnew.ecache.service.EmployeeService;
import com.mingnew.ecache.util.Result;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author : lk
 * @date 2021/5/1 21:39
 **/
@RestController
@RequestMapping("/cache/test")
@Api(value = "缓存控制器")
@CrossOrigin
public class EhcacheController {


    @Autowired
    private EmployeeService employeeService;


    @ApiOperation(value = "查询信息", notes = "查询信息", httpMethod = "GET", response = Map.class)
    @ApiResponses(
            {@ApiResponse(code = 200, message = "处理成功"),
                    @ApiResponse(code = 500, message = "处理失败")})
    @GetMapping("test")
    public Map<String, Object> test() {
        Map<String, Object> map = new HashMap<>(16);
        map.put("code", 200);
        map.put("data", "返回所有的数据");
        return map;
    }

    /**
     * 查询所有的员工信息
     *
     * @return 返回 所有的信息
     */
    @ApiOperation(value = "查询员工信息",notes = "查询所有的员工信息",response = Result.class)
    @ApiResponse(code = 0,message = "处理成功",response = Result.class)
    @PostMapping("employeeList")
    public Result employeeList(@RequestBody EmployeeDto employeeDto) {
        return employeeService.selectList(employeeDto);
    }


    @PostMapping("updateEmployee")
    @ApiOperation(value = "修改员工信息",notes = "根据id修改员工姓名")
    @ApiResponse(code = 0,message = "处理成功")
    public Result updateEmployee( @ApiParam(name = "employeeVo") @RequestBody EmployeeVo employeeVo) {
        employeeService.updateEmployeeById(employeeVo);
        return  Result.success();
    }
    @PostMapping("getEmp")
    @ApiOperation(value = "获取员工信息",notes = "根据id获取对应的员工信息")
    @ApiResponse(code = 0,message = "处理成功")
    @ApiImplicitParam(name = "id",value = "1",required = false)
    public Result getEmp( Integer id) {
        return  Result.success(employeeService.getEmp(id));
    }




    @ApiOperation(value = "删除员工信息",notes = "删除员工信息")
    @ApiResponse(code = 0,message = "处理成功")
    @PostMapping("deleteEmployee")
    public Result deleteEmployee(@RequestBody Employee employee) {
        employeeService.deleteEmployee(employee.getId());
        return  Result.success();
    }

}
